package com.java.admin.service.impl;

import com.java.admin.service.CategoryService;
import com.java.clients.CategoryClient;
import com.java.param.PageParam;
import com.java.pojo.Category;
import com.java.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryClient categoryClient;

    @Cacheable(value = "list.category",key = "#pageParam.currentPage+'-'+#pageParam.pageSize")
    @Override
    public R list(PageParam pageParam) {
        R r = categoryClient.adminList(pageParam);
        log.info("CategoryServiceImpl.list 业务已经完成,结果:{}", r);
        return r;
    }

    /**
     * 保存类别信息
     *
     * @param category
     * @return
     */
    @CacheEvict(value = "list.category",allEntries = true)
    @Override
    public R save(Category category) {
        R r = categoryClient.adminSave(category);
        log.info("CategoryServiceImpl.save 业务已经完成,结果:{}", r);
        return r;
    }

    /**
     * 删除类别信息
     *
     * @param category
     * @return
     */
    @CacheEvict(value = "list.category",allEntries = true)
    @Override
    public R remove(Category category) {
        R r = categoryClient.adminRemove(category);
        log.info("CategoryServiceImpl.remove 业务已经完成,结果:{}", r);
        return r;
    }

    /**
     * 更新类别信息
     *
     * @param category
     * @return
     */
    @CacheEvict(value = "list.category",allEntries = true)
    @Override
    public R update(Category category) {
        R r = categoryClient.adminUpdate(category);
        log.info("CategoryServiceImpl.update 业务已经完成,结果:{}", r);
        return r;
    }
}
